import { marked } from 'marked'
/**
 * 自动导入md 注册插件
 * @param {} options 
 * @returns 
 */
export default function (options) {
  return {
    name: "vite-plugin-markdown",
    enforce: "pre",
    async transform(code, id) {
      if (id.endsWith(".md")) {
        return {
          code: `import {h, defineComponent} from "vue";
                const article = defineComponent({
                    name: "Markdown",
                }).render =() => {
                    return h("div", {
                      id: "write",
                      innerHTML: '${marked(code).trimEnd()}'
                    })
                };
                export default article`,
          map: null,
        };
      }
    },
  };
}


